package com.share.wechat.common;

import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

/**
 * 控制器层的父类
 * Created by er on 2017/12/18.
 */
@AutoConfigureMockMvc
public class AbstractTestUseCaseController extends AbstractTestUseCase {

    @Autowired
    private MockMvc mockMvc;// 模拟MVC对象，通过MockMvcBuilders.webAppContextSetup(this.wac).build()初始化。
    // 模拟context
    @Autowired
    private WebApplicationContext wac;//注入WebApplicationContext
    //模拟session
    @Autowired
    private MockHttpSession session;
    //模拟request
    @Autowired
    private MockHttpServletRequest request;


    @Before // 在测试开始前初始化工作
    public void setup() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    }


    public WebApplicationContext getWac() {
        return wac;
    }

    public MockHttpSession getSession() {
        return session;
    }

    public MockHttpServletRequest getRequest() {
        return request;
    }

    public MockMvc getMockMvc() {
        return mockMvc;

    }
}
